/*
 * MIT License
 *
 * Copyright (c) 2023 北京凯特伟业科技有限公司
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.je.bpm.engine.management;

import java.util.List;
import java.util.Map;

/**
 * Data structure used for retrieving database table content.
 */
public class TablePage {

    protected String tableName;

    /**
     * The total number of rows in the table.
     */
    protected long total = -1;

    /**
     * Identifies the index of the first result stored in this TablePage. For example in a paginated database table, this value identifies the record number of the result on the first row.
     */
    protected long firstResult;

    /**
     * The actual content of the database table, stored as a list of mappings of the form {column name, value}.
     * <p>
     * This means that every map object in the list corresponds with one row in the database table.
     */
    protected List<Map<String, Object>> rowData;

    public TablePage() {

    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    /**
     * @return the start index of this page (ie the index of the first element in the page)
     */
    public long getFirstResult() {
        return firstResult;
    }

    public void setFirstResult(long firstResult) {
        this.firstResult = firstResult;
    }

    public void setRows(List<Map<String, Object>> rowData) {
        this.rowData = rowData;
    }

    /**
     * @return the actual table content.
     */
    public List<Map<String, Object>> getRows() {
        return rowData;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    /**
     * @return the total rowcount of the table from which this page is only a subset.
     */
    public long getTotal() {
        return total;
    }

    /**
     * @return the actual number of rows in this page.
     */
    public long getSize() {
        return rowData.size();
    }
}
